package com.lagou.homework1_4;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class ScannerStrSort {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        String str = null;

        //循环录入
        while(!"end".equalsIgnoreCase(str)) {
            Scanner sc = new Scanner(System.in);
            str = sc.next();
            list.add(str);
        }

        //排序-倒序
        list.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                    return o1.compareTo(o2) * -1;
            }
        });

        //写入abc.txt
        FileWriter fw = null;
        try {
            fw = new FileWriter("d:/abc.txt");
            for (String s: list) {
                fw.write(s + " ");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(null != fw) {
                try {
                    fw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
